<template>
  <div class="wrap-wrap">
    <div class="title">
      <h2>推荐鲜花</h2>
    </div>
    <div class="wrap" v-for="item in goods" :key="item.id"  @click="toDetails(item.id)">
      <div class="left">
        <img :src="item.pic" alt="">
      </div>
      <div class="right">
        <h2>{{item.name}}</h2>
        <p class="dis">{{item.characteristic ? item.characteristic: '' | filterDes}}</p>
        <div class="price">
          <div class="price-text">&yen;{{item.minPrice}}</div>
          <van-icon class-prefix="icon" name="gouwuche" size="24" @click.stop=addCart(item.id)></van-icon>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    goods: {
      type: Array,
      required: true
    }
  },
  filters: {
    filterDes (val) {
      if (val.length >= 10) {
        return val.substr(0, 10) + '...'
      } else {
        return val
      }
    }
  },
  methods: {
    toDetails (id) {
      this.$router.push({
        path: '/detail',
        query: {
          id
        }
      })
    },
    addCart (id) {
      // 点击加入购物车，子组件不操作，由父组件完成
      this.$emit('addCart', id)
    }
  }
}
</script>

<style lang="scss" scoped>
.wrap-wrap{
  .title{
    font-size: 24px;
    font-weight: bold;
    text-align: center;
    padding:20px;
    color: red;
  }
  .wrap{
  background-color: #fff;
  display: flex;
  border: 1px solid #ccc;
    .left{
      img{
        width: 150px;
        height: 150px;
        display: block;
      }
    }
    .right{
      display: flex;
      flex-direction: column;
      color: #555;
      flex: 1;
      padding: 15px 20px;
      h2{
        font-size: 18px;
        font-weight: bold;
        color: blue;
      }
      .dis{
        flex: 1;
        padding-top: 25px;
      }
      .price{
        display: flex;
        align-items: center;
        .price-text{
          padding-top: 8px;
          font-size: 18px;
          color: red;
          font-weight: bold;
          flex: 1;
        }
      }
    }

}
}
</style>
